package com.pengtu.entity.asset.Message;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Where;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.Attachment;
import com.pengtu.entity.app.Department;
import com.pengtu.entity.app.User;

@Entity
@Table(name = "T_ASST_REGULATIONS")
public class Regulations extends IdEntity {




	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String title; // 制度标题
	private Date publishDate; // 发布时间
	private User publishPerson; // 发布人
	private Department department; // 发布部门
	private String publishScope; // 发布范围
	private String keyword; // 关键字
	private String publishContent; // 制度内容
	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(new Comparator<Attachment>() {
		@Override
		public int compare(Attachment attFirst, Attachment attSecond) {
			// TODO Auto-generated method stub
			return attFirst.getCreateDate().compareTo(attSecond.getCreateDate());
		}
	});                        //附件
	private String state; // 状态
	private String regulationType; // 制度类型
	
	@Column(name = "TITLE")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "PUBLISHDATE")
	@Temporal(TemporalType.DATE)
	public Date getPublishDate() {
		return publishDate;
	}

	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	@ManyToOne
	@JoinColumn(name="PUBLISHPERSON")
	public User getPublishPerson() {
		return publishPerson;
	}

	public void setPublishPerson(User publishPerson) {
		this.publishPerson = publishPerson;
	}

	@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
	@JoinColumn(name="DEPARTMENT")
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	@Column(name = "PUBLISHSCOPE")
	public String getPublishScope() {
		return publishScope;
	}

	public void setPublishScope(String publishScope) {
		this.publishScope = publishScope;
	}

	@Column(name = "KEYWORD")
	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	@Column(name = "PUBLISHCONTENT")
	public String getPublishContent() {
		return publishContent;
	}

	public void setPublishContent(String publishContent) {
		this.publishContent = publishContent;
	}


	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	@Where(clause="delFlag = 0")
	public Set<Attachment> getAttachmentSet() {
		return attachmentSet;
	}
	
	public void setAttachmentSet(Set<Attachment> attachmentSet) {
		
		this.attachmentSet = attachmentSet;
	}
	
	@Transient
	public Attachment getAttachment(){
		if(attachmentSet.iterator().hasNext())
		return attachmentSet.iterator().next();
		return new Attachment();
	}

	public void setAttachment(Attachment attachment){
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}

	@Column(name = "STATE")
	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}
	@Column(name = "REGULATIONTYPE")
	public String getRegulationType() {
		return regulationType;
	}

	public void setRegulationType(String regulationType) {
		this.regulationType = regulationType;
	}


	public Regulations() {
		super();
	}

}
